package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.QuickChangeConfigBean;
import com.koron.css2.baseConfig.mapper.QuickChangeConfigMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class UserChangeQuickConfigSave  implements ServerInterface{
	
	private Logger log = LogManager.getLogger(UserChangeQuickConfigSave.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			List<QuickChangeConfigBean> beans = JsonUtils.jsonToList(JsonUtils.objectToJson(req.getData()),QuickChangeConfigBean.class);
			QuickChangeConfigMapper mapper = factory.getMapper(QuickChangeConfigMapper.class);
			for (QuickChangeConfigBean str : beans){
				QuickChangeConfigBean bean = new QuickChangeConfigBean();
				bean.setCode(str.getCode());
				bean.setIsUse(str.getIsUse());
				mapper.update(bean);
			}
		}catch(Exception e) {
			log.error("快速变更配置失败",e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "快速变更配置失败", void.class);
		}
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	}

}
